package com.zz.springboot.manager.impl;

import com.zz.springboot.anno.ImportExcelMark;
import com.zz.springboot.dto.DataDTO;
import com.zz.springboot.manager.AoMenManager;
import com.zz.springboot.mapper.AoMenMapper;
import com.zz.springboot.model.AoMen;
import com.zz.springboot.model.ExcludeInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class AoMenManagerImpl implements AoMenManager {

    @Autowired
    AoMenMapper aoMenMapper;

    @Override
    public List<Integer> selectAllNums() {
        List<Integer> numSet = aoMenMapper.selectAllNums();
        if (CollectionUtils.isEmpty(numSet)) {
            numSet = new ArrayList<>();
        }
        return numSet;
    }

    @Override
    public List<DataDTO> selectAllData() {
        List<DataDTO> allData = aoMenMapper.selectAllData();
        if (CollectionUtils.isEmpty(allData)) {
            allData = new ArrayList<>();

        }
        return allData;
    }

    @Override
    @ImportExcelMark
    public Integer insertBatchData(List<DataDTO> dataDTOList) {
        return aoMenMapper.insertData(dataDTOList);
    }

    @Override
    //@ImportExcelMark
    public Integer insertAoMenData(List<AoMen> dataList) {
        return aoMenMapper.insertAoMenData(dataList);
    }

    @Override
    public void updateBatchData(List<DataDTO> dataDTOList) {
        aoMenMapper.updateBatchData(dataDTOList);

    }

    @Override
    public List<ExcludeInfo> getAllExcludeInfo() {
        List<ExcludeInfo> allExcludeInfo = aoMenMapper.getAllExcludeInfo();
        if (CollectionUtils.isEmpty(allExcludeInfo)) {
            allExcludeInfo = new ArrayList<>();
        }
        return allExcludeInfo;
    }


    public void clearTable() {
        aoMenMapper.clearAoMenTable();
    }

    @Override
    public List<DataDTO> selectOddsOrEvensData(String category) {
        List<DataDTO> data = aoMenMapper.selectOddsOrEvensData(category);

        return data == null ? new ArrayList<>() : data;
    }

    @Override
    public List<DataDTO> selectBigLittle(String category) {
        List<DataDTO> data =aoMenMapper.selectBigLittleData(category);
        return data == null ? new ArrayList<>() : data;
    }

    @Override
    public List<DataDTO> selectColorData(String category) {
        List<DataDTO> data =aoMenMapper.selectColorData(category);
        return data == null ? new ArrayList<>() : data;
    }

    @Override
    public List<DataDTO> selectAnimalsData(String category) {
        List<DataDTO> data =aoMenMapper.selectAnimalsData(category);
        return data == null ? new ArrayList<>() : data;
    }

    @Override
    public List<DataDTO> selectTailData(String category) {
        List<DataDTO> data =aoMenMapper.selectTailData(category);
        return data == null ? new ArrayList<>() : data;
    }

    /**
     * 获得存在集合originDataDTOList中、但不存在集合numSet中的号码
     *
     * @param dataDTOList
     * @param numSet
     * @return
     */
    public List<DataDTO> getInsertData(List<DataDTO> dataDTOList, List<Integer> numSet) {

        return dataDTOList.stream().filter(u -> !numSet.contains(u.getNum())).collect(Collectors.toList());
    }

    /**
     * 获得存在集合originDataDTOList中、且存在集合numSet中的号码（待更新）
     *
     * @return
     */
    public List<DataDTO> getUpdateData(List<DataDTO> dataDTOList, List<Integer> numSet) {
        return dataDTOList.stream().filter(u -> numSet.contains(u.getNum())).collect(Collectors.toList());
    }
}
